﻿using Base.WCS.Common;
using Base.WCS.Entity;
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Base.ClientUI {
    public class TaskUtil {
        static Dictionary<String ,String> myDictionary = new Dictionary<String ,String>();


        static TaskUtil() {
             myDictionary.Add("detail.devicetype.1" ,"垛机");
            myDictionary.Add("detail.devicetype.2" ,"输送线");
            myDictionary.Add("detail.devicetype.3" ,"RGV");
            myDictionary.Add("detail.devicetype.4" ,"机器人");
            myDictionary.Add("detail.devicetype.5" ,"软件");
             myDictionary.Add("crane.motiontype.-1" ,"删除");
            myDictionary.Add("crane.motiontype.1" ,"取货");
            myDictionary.Add("crane.motiontype.2" ,"放货");
            myDictionary.Add("crane.status.11" ,"待执行");
            myDictionary.Add("crane.status.12" , "已经接收");
            myDictionary.Add("crane.status.17" , "起始位置可用");
            myDictionary.Add("crane.status.20" , "到起始位置");
            myDictionary.Add("crane.status.25" , "取货");
            myDictionary.Add("crane.status.30" , "空取");
            myDictionary.Add("crane.status.40" , "取货完成");

            myDictionary.Add("crane.status.42", "放货行走中");
            myDictionary.Add("crane.status.45", "离开原货位");
            myDictionary.Add("crane.status.50", "达到目标位置");
            myDictionary.Add("crane.status.70", "满放变更");
            myDictionary.Add("crane.status.75", "放货中");
            myDictionary.Add("crane.status.80" , "完成");

         
       



             myDictionary.Add("carrier.status.1" ,"待执行");
            myDictionary.Add("carrier.status.2" ,"执行中");
            myDictionary.Add("carrier.status.3" ,"完成");
             myDictionary.Add("complete.status.1" ,"待执行");
            myDictionary.Add("complete.status.2" ,"执行中");
            myDictionary.Add("complete.status.9" ,"完成");
            myDictionary.Add("complete.status.-1" ,"删除");
             myDictionary.Add("detail.ralyforbid.1" ,"不可执行");
            myDictionary.Add("detail.ralyforbid.0" ,"可执行");
             myDictionary.Add("detail.status.1" ,"待执行");
            myDictionary.Add("detail.status.2" ,"执行中");
            myDictionary.Add("detail.status.9" ,"完成");
            myDictionary.Add("detail.status.-1" ,"已删除");
             myDictionary.Add("detail.type.1" ,"入库");
            myDictionary.Add("detail.type.2" ,"出库");
            myDictionary.Add("detail.type.3" ,"移库");
            myDictionary.Add("detail.type.4" ,"渡库");
            myDictionary.Add("complete.tasktype.1" ,"入库");
            myDictionary.Add("complete.tasktype.2" ,"出库");
            myDictionary.Add("complete.tasktype.3" ,"移库");
            myDictionary.Add("complete.tasktype.4" ,"渡库");
            myDictionary.Add("complete.tasktype.5" ,"出入");
            myDictionary.Add("complete.tasktype.6" ,"盘库");
              myDictionary.Add("crane.classtypedisplay.crane" ,"垛机");
            myDictionary.Add("humen.classtypedisplay.humen" ,"人工");
            myDictionary.Add("carrier.classtypedisplay.carrier" ,"传输线");
            myDictionary.Add("CompleteParam.status.1" ,"新建");
            myDictionary.Add("CompleteParam.status.2" ,"可分解");
            myDictionary.Add("CompleteParam.status.3" ,"分解完成");
            myDictionary.Add("CompleteParam.status.6" ,"单步撤销");
            myDictionary.Add("CompleteParam.status.-1" ,"删除");
            myDictionary.Add("CompleteParam.status.-2" ,"终止");
            myDictionary.Add("CompleteParam.status.9" ,"执行完成");
             myDictionary.Add("CompleteParam.type.1" ,"起始");
            myDictionary.Add("CompleteParam.type.2" ,"托盘搬运");
            myDictionary.Add("CompleteParam.type.3" ,"机器人分解");
            myDictionary.Add("CompleteParam.type.4" ,"软件任务");
            myDictionary.Add("CompleteParam.type.5" ,"依赖托盘搬运");
            myDictionary.Add("CompleteParam.type.9" ,"结束");
        }
        public static bool warning(String info)
        {
            var res = MessageBox.Show(info, "警告", MessageBoxButtons.YesNo,
                     MessageBoxIcon.Warning);
            if (res == DialogResult.Yes)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static List<BaseTask> margin<T1, T2>(List<T1> l1, List<T2> l2) where T1 : BaseTask where T2 : BaseTask
        {
            List<BaseTask> resList = new List<BaseTask>();
            T1 t1 = null;
            T2 t2 = null;
            if (l1 == null)
            {
                l1 = new List<T1>();
            }
            if (l2 == null)
            {
                l2 = new List<T2>();
            }
            while (true)
            {
                 if (l1.Count > 0 && t1 == null)
                {
                    t1 = l1[0];
                }
                if (l2.Count > 0 && t2 == null)
                {
                    t2 = l2[0];
                }
                 if (t1 == null && t2 == null)
                {
                    break;
                }
                else if (t1 == null && t2 != null)
                {
                    resList.Add(t2);
                    l2.Remove(t2);
                    t2 = null;
                }
                else if (t1 != null && t2 == null)
                {
                    resList.Add(t1);
                    l1.Remove(t1);
                    t1 = null;
                }
                else
                {
                    
                    if (t1.myOrder > t2.myOrder )
                    {
                        resList.Add(t2);
                        l2.Remove(t2);
                        t2 = null;
                    }
                    else
                    {
                        resList.Add(t1);
                        l1.Remove(t1);
                        t1 = null;
                    }
                }
            }
            return resList;
        }
          private static Object lockObj = new Object();
         static public String getDisplayName(String name,String value) {
            String key = name + value;
            if( myDictionary.ContainsKey(key) ) {
                return myDictionary[key];
            } else {
                return value.ToString();
            }
        
        }
     }
}
